package org.command.main.BS;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

// 2. 创建一个联系人服务类
@Service
public class ContactService {
    private final List<Contact> contacts = new ArrayList<>();
    {
        contacts.add(new Contact("Tom", "main123", "1587265874"));
    }
    public List<Contact> getAllContacts() {
        return contacts;
    }

    public void addContact(Contact contact) {
        contacts.add(contact);
    }

    public void updateContact(String name, Contact updatedContact) {
        // 实现更新联系人的逻辑
        contacts.forEach(con -> {
            if (con.getName().equals(name)) {
                con.setAddress(updatedContact.getAddress());
                con.setPhoneNumber(updatedContact.getPhoneNumber());
            }
        });
    }

    public void deleteContact(String name) {
        // 实现删除联系人的逻辑
        contacts.removeIf(con -> {
            return con.getName().equals(name);
        });
    }
}

